package com.qcby.Controller;

import com.qcby.Entity.City;
import com.qcby.Service.CityService;
import com.qcby.query.CityQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/City")
public class CityController {

    @Autowired
    private CityService cityService;

    @CrossOrigin
    @RequestMapping("/getCityWithStations")
    public List<CityQuery> getCityWithStations(){
        return cityService.getCityWithStations();
    }

    @CrossOrigin
    @GetMapping("/getCityById")
    public City getCityById(Integer id) {
        return cityService.selectByPrimaryKey(id);
    }

    @CrossOrigin
    @PostMapping("/insertCity")
    public City createCity(@RequestBody City city) {
        //System.out.println(city.getName());
        cityService.insert(city);
        return city;
    }

    @CrossOrigin
    @PutMapping("/updateCity")
    public City updateCity(@RequestBody City city) {
        cityService.updateByPrimaryKey(city);
        return city;
    }

    @CrossOrigin
    @DeleteMapping("/deleteCity")
    public void deleteCity(Integer id) {
        cityService.deleteByPrimaryKey(id);
    }

    @CrossOrigin
    @RequestMapping("/getCityNumByCityName")
    public int getCityNumByCityName(City city){
        //System.out.println(cityService.getCityNumByCityName(city));
        return cityService.getCityNumByCityName(city);
    }

    @CrossOrigin
    @GetMapping("/getAllCity")
    public List<City> getAllCity(){
        return cityService.getAllCity();
    }
}
